{% extends 'layouts/base.html' %}
{% import 'macros/form_macros.html' as f %}
{% import 'macros/check_password.html' as check %}

{% block scripts %}
{% endblock %}

{% block content %}
    <div class="ui stackable centered grid container">
        <div class="twelve wide column">
            <a class="ui basic compact button" href="{{ url_for('admin.index') }}">
                <i class="caret left icon"></i>
                Back to dashboard
            </a>
            <h2 class="ui header">
                Add New User
                <div class="sub header">Create a new user account</div>
            </h2>

            {% set flashes = {
                'error':   get_flashed_messages(category_filter=['form-error']),
                'warning': get_flashed_messages(category_filter=['form-check-email']),
                'info':    get_flashed_messages(category_filter=['form-info']),
                'success': get_flashed_messages(category_filter=['form-success'])
            } %}

            {{ f.begin_form(form, flashes) }}

                {{ f.render_form_field(form.role) }}

                <div class="two fields">
                    {{ f.render_form_field(form.first_name) }}
                    {{ f.render_form_field(form.last_name) }}
                </div>

                {{ f.render_form_field(form.email) }}

                {% if form.password %}

                    <div class="two fields">
                        {{ f.render_form_field(form.password) }}
                        {{ f.render_form_field(form.password2) }}
                    </div>

                {% endif %}

                {{ f.form_message(flashes['error'], header='Something went wrong.', class='error') }}
                {{ f.form_message(flashes['warning'], header='Check your email.', class='warning') }}
                {{ f.form_message(flashes['info'], header='Information', class='info') }}
                {{ f.form_message(flashes['success'], header='Success!', class='success') }}

                {% for field in form | selectattr('type', 'equalto', 'SubmitField') %}
                    {{ f.render_form_field(field) }}
                {% endfor %}

            {{ f.end_form() }}
            {% if form.password %} 
              {{ check.password_check('password', 0) }} 
            {% endif %}
        </div>
    </div>
{% endblock %}
